package edu.pku.sei.transformation.editor.model.goal;

import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.transformation.editor.model.ModelPackage;

public class Description extends MetaModelElement {
	private String summary = "new description";
	private String content = "";

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		String oldValue = this.summary;
		if (oldValue == null || !oldValue.equals(summary)) {
			this.summary = summary;
			firePropertyChange(ModelPackage.DESCRIPTION_SUMMARY, oldValue,
					summary);
			if (this.container != null) {
				this.container.firePropertyChange(
						ModelPackage.DESCRIPTION_SUMMARY, oldValue, summary);
			}
		}
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		String oldValue = this.content;
		if (oldValue == null || !oldValue.equals(content)) {
			this.content = content;
			firePropertyChange(ModelPackage.DESCRIPTION_CONTENT, oldValue,
					content);
			if (this.container != null) {
				this.container.firePropertyChange(
						ModelPackage.DESCRIPTION_CONTENT, oldValue, content);
			}
		}
	}

	@Override
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root,
				ModelPackage.DESCRIPTION_SUMMARY, summary);
		XMLUtility.xmlInstance.serializeAttribute(root,
				ModelPackage.DESCRIPTION_CONTENT, content);
	}

	@Override
	public void deSerialize(Element root) {
		super.deSerialize(root);
		summary = XMLUtility.xmlInstance.deSerializeString(root,
				ModelPackage.DESCRIPTION_SUMMARY);
		content = XMLUtility.xmlInstance.deSerializeString(root,
				ModelPackage.DESCRIPTION_CONTENT);
	}

	@Override
	public String toString() {
		if (summary == null || summary.equals(""))
			return "default";
		else
			return summary;
	}
}
